import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

//此处路径必须写为/开头
@WebServlet("/hello")
public class HelloServlet extends HttpServlet {
    @Override
    public void init() throws ServletException {
        //重写init, 可插入自己的初始化逻辑
        System.out.println("init");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        程序猿就需要在doGet，根据请求req,结合咱们自己的业务逻辑构造出一个resp 对象来.

//  服务器控制台打印
        System.out.println("hello world!");
//  返回到客户端getWriter().write()
        resp.getWriter().write("hello world!!! doget");
    }



    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.service(req, resp);

    }

    @Override
    public void destroy() {
        System.out.println("destroy");
    }
}
